<?php
class Sb_Http
{
	const DEFAULT_LAYOUT = 'Site';
	
    private static $_instance;
    private $controllerName;
    private $actionName;
    private $layoutName;

    public static function getInstance()
    {
        if(self::$_instance === null){
            self::$_instance = new self();
        }
        
        return self::$_instance;
    }

    private function __construct()
    {
        $this->initParams();
    }

    public function __get($paramName)
    {
        return $this->$paramName;
    }

    public function __set($paramName, $paramVal)
    {
        $this->$paramName = $paramVal;
    }
    
    public function getParam($paramName)
    {
    	return isset($_REQUEST[$paramName]) ? $_REQUEST[$paramName] : null;
    }

    public function getModuleName()
    {
        return $this->getLayoutName();
    }

    private function initParams()
    {
        $this->controllerName = 'Index';
        $this->actionName = 'index';
        if(isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])){
            $queryStringArr = explode('/', $_SERVER['QUERY_STRING']);
            if(count($queryStringArr)){
                if(isset($queryStringArr[0])  && !empty($queryStringArr[0])){
                    $this->controllerName = ucFirst($queryStringArr[0]);
                }
                if(isset($queryStringArr[1])  && !empty($queryStringArr[1])){
                    $this->actionName = $queryStringArr[1];
                }
            }
        }
        //var_dump(ucFirst(basename($_SERVER['SCRIPT_NAME'], '.php')));
        $this->layoutName = str_replace('Index', self::DEFAULT_LAYOUT, ucFirst(basename($_SERVER['SCRIPT_NAME'], '.php')));
       // var_dump($this->layoutName);
    }

    public function getBaseUrl()
    {
        var_dump($_SERVER);
    }

    public function getControllerName()
    {
       return $this->controllerName;
    }

    public function getActionName()
    {
        return $this->actionName;
    }

    public function getLayoutName()
    {
        return $this->layoutName;
    }
}